<template>
	<view>
		<view
			style="display: flex;flex-direction: column; margin: 50rpx auto 20rpx auto;width: 80%;background-color: white;border-radius: 20rpx;box-shadow: 1px 1px 5px #c2c2c2;padding: 30rpx;">
			<view style="display: flex; width: 100%;flex-direction: row;align-items: center;">
				手机号
				<uni-easyinput style="width: 100%; border-radius: 15rpx;height: 80rpx;margin-left: 25rpx; "
					v-model="tel" type="number" placeholder="请输入手机号" />
			</view>
			<view style="display: flex; width: 100%;flex-direction: row;align-items: center;margin-top: 30rpx;">
				姓名
				<uni-easyinput style="width: 100%; border-radius: 15rpx;height: 80rpx;margin-left: 25rpx; "
					v-model="name" type="text" placeholder="请输入老师/家长姓名" />
			</view>
			<view style="display: flex; width: 100%;flex-direction: row;align-items: center;margin-top: 30rpx;">
				身份
				<picker @change="bindPickerChange" :range="shu1" style="width: 80%;">
					<uni-easyinput style="width: 100%; border-radius: 15rpx;height: 80rpx;margin-left: 25rpx; "
						type="text" v-model="shenfen" placeholder="请选择身份家长/老师" suffixIcon="bottom" />
				</picker>
			</view>
			<view style="display: flex; width: 100%;flex-direction: row;align-items: center;margin-top: 30rpx;">
				密码
				<uni-easyinput style="width: 100%; border-radius: 15rpx;height: 80rpx;margin-left: 25rpx; "
					v-model="mima" type="password" placeholder="请输入密码" />
			</view>
			<view style="display: flex; width: 100%;flex-direction: row;align-items: center;margin-top: 30rpx;">
				重复密码
				<uni-easyinput style="width: 100%; border-radius: 15rpx;height: 80rpx;margin-left: 25rpx; "
					v-model="remima" type="password" placeholder="再输入一次密码" />
			</view>
		</view>
		<view @click="zhuce"
			style="display: flex;width: 40%;margin: 100rpx auto 50rpx auto;background-color: blue;border-radius: 20rpx;color: white;font-weight: bold;padding: 20rpx;align-items: center;justify-content: center;">
			注 册
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				meiyi_userinfo: {},
				item: {},
				name: '',
				tel: '',
				mima: '',
				remima: '',
				shenfen: '',
				shu1: ["家长", "老师"],
			}
		},
		onLoad() {
			this.islogin()


		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.shenfen = this.shu1[e.detail.value]
			},
			// 注册新信息到数据库
			zhuce() {
				if (this.mima !== this.remima) {
					uni.showToast({
						title: '两次密码填写不一致！',
						icon: 'none',
						duration: 1000
					})
					return
				}
				this.item.tel = this.tel
				this.item.name = this.name
				this.item.shenfen = this.shenfen
				this.item.mima = this.mima
				if (!this.name | !this.tel | !this.tel | !this.mima) {
					uni.showToast({
						title: '请填写好各项资料再进行提交！',
						icon: 'none',
						duration: 1000
					})
					return
				}
				const db = uniCloud.database();
				db.collection('meiyi_userinfo')
					.add(this.item)
					.then((res) => {
						uni.showToast({
							title: '注册成功',
							icon: 'none',
							duration: 1000
						})
						this.item._id = res.result.id
						// console.log("name",this.item)
						uni.setStorageSync('meiyi_userinfo', this.item)
						uni.reLaunch({
							url: '/pages/shouye/shouye'
						});
					}).catch((err) => {
						console.log(err)
						uni.showToast({
							title: '注册失败，请检查本手机号是否已注册'
						})
					})

			},
		}
	}
</script>

<style>

</style>